mruby 4.0.0
mruby is the lightweight implementation of the Ruby language
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1
6
7#ifndef MRUBY_COMMON_H
8#define MRUBY_COMMON_H
9
10#ifdef __APPLE__
11 #ifndef __TARGETCONDITIONALS__
12 #include "TargetConditionals.h"
13 #endif
14#endif
15
16#ifdef __cplusplus
17#ifdef MRB_USE_CXX_ABI
18#define MRB_BEGIN_DECL
19#define MRB_END_DECL
20#else
21# define MRB_BEGIN_DECL extern "C" {
22# define MRB_END_DECL }
23#endif
24#else
26# define MRB_BEGIN_DECL
28# define MRB_END_DECL
29#endif
30
31#include <sys/types.h>
32#if defined _MSC_VER
33#include <BaseTsd.h>
34typedef SSIZE_T ssize_t;
35#endif
36
41
43#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L
44# define mrb_noreturn _Noreturn
45#elif defined __GNUC__ && !defined __STRICT_ANSI__
46# define mrb_noreturn __attribute__((noreturn))
47#elif defined _MSC_VER
48# define mrb_noreturn __declspec(noreturn)
49#else
50# define mrb_noreturn
51#endif
52
54#if defined __GNUC__ && !defined __STRICT_ANSI__
55# define mrb_deprecated __attribute__((deprecated))
56#elif defined _MSC_VER
57# define mrb_deprecated __declspec(deprecated)
58#else
59# define mrb_deprecated
60#endif
61
63#if defined(__GNUC__) || defined(__clang__)
64# define mrb_likely(x) __builtin_expect(!!(x), 1)
65# define mrb_unlikely(x) __builtin_expect(!!(x), 0)
66#else
67# define mrb_likely(x) (x)
68# define mrb_unlikely(x) (x)
69#endif
70
72#ifndef mrb_alignas
73# if defined(__cplusplus) && __cplusplus >= 201103L
74# // https://en.cppreference.com/w/cpp/language/alignas
75# define mrb_alignas(n) alignas(n)
76# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
77# // https://en.cppreference.com/w/c/language/_Alignas
78# define mrb_alignas(n) _Alignas(n)
79# elif defined(_MSC_VER) || defined(__INTEL_COMPILER)
80# // https://learn.microsoft.com/en-us/cpp/cpp/align-cpp?view=msvc-170
81# define mrb_alignas(n) __declspec(align(n))
82# elif defined(__GNUC__) || defined(__clang__)
83# // https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-aligned-type-attribute
84# define mrb_alignas(n) __attribute__((aligned(n)))
85# else
86# // `mrb_alignas` defined as dummy. If necessary, send issues to https://github.com/mruby/mruby .
87# define mrb_alignas(n)
88# endif
89#endif
90
92#if defined _MSC_VER && _MSC_VER < 1900
93# ifndef __cplusplus
94# define inline __inline
95# endif
96#endif
97#define MRB_INLINE static inline
98
100#ifndef MRB_API
101#if defined(MRB_BUILD_AS_DLL)
102#if defined(MRB_CORE) || defined(MRB_LIB)
103# define MRB_API __declspec(dllexport)
104#else
105# define MRB_API __declspec(dllimport)
106#endif
107#else
108# define MRB_API extern
109#endif
110#endif
111
113#if defined(__MINGW32__) || defined(__MINGW64__)
114# include <_mingw.h>
115# if defined(__MINGW64_VERSION_MAJOR)
116# define MRB_MINGW64_VERSION (__MINGW64_VERSION_MAJOR * 1000 + __MINGW64_VERSION_MINOR)
117# elif defined(__MINGW32_MAJOR_VERSION)
118# define MRB_MINGW32_VERSION (__MINGW32_MAJOR_VERSION * 1000 + __MINGW32_MINOR_VERSION)
119# endif
120# if defined(__MINGW32__) && !defined(__MINGW64__)
121# define MRB_MINGW32_LEGACY
122# endif
123#endif
124
126
127#endif /* MRUBY_COMMON_H */
#define MRB_END_DECL
End declarations in C mode.
Definition common.h:28
#define MRB_BEGIN_DECL
Start declarations in C mode.
Definition common.h:26